home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / USBModem / ShimSerialStub.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-25  |  5.2 KB  |  192 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        ShimSerialStub.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1998-2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Errors.h>
  13. #include <LowMem.h>
  14. #include <TextUtils.h>
  15.  
  16. #include "Modem.h"
  17. #include "ModemVersion.h"
  18. #include "ShimSerialStub.h"
  19.  
  20. //
  21. //    Statically define the Icon & Icon Mask for
  22. //    the CRM structures.  In the new world 
  23. //    (this was Rhapsody) we don't have resources 
  24. //    so we have to do it the hard way.
  25. //    This doesn't make sense anymore we should
  26. //    change this to support resource based icons
  27. //
  28.  
  29. UInt32 CRMDeviceIcon[] = {
  30.     0xFFFFFFFF, 0x80000001, 0x80018001, 0x80018001,
  31.     0x80024001, 0x80042001, 0x80042001, 0x80081001,
  32.     0x800E7001, 0x80024FC1, 0x80C24841, 0x81224841,
  33.     0x82124841, 0x82124CC1, 0x82124501, 0x81224901,
  34.     0x80A25201, 0x80926401, 0x804A0801, 0x80261001,
  35.     0x80102001, 0x80084001, 0x80044001, 0x80024001,
  36.     0x80042001, 0x80081001, 0x80081001, 0x80081001,
  37.     0x80042001, 0x8003C001, 0x80000001, 0xFFFFFFFF,
  38.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  39.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  40.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  41.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  42.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  43.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  44.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  45.     0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
  46. };
  47.  
  48. /***********************************************************************************/
  49. //    Function:        InstallShimDrvr(CFragConnectionID    ConnID)
  50. //    Description:    Handles the interface with the shim install
  51. //
  52. //    Input:            CFrag Connection ID (mine)
  53. //    Output:            Results
  54. /***********************************************************************************/
  55.  
  56. OSErr InstallShimDrvr(CFragConnectionID    ConnID)
  57. {
  58.     OSErr                 err;
  59.     ShimRefNum            Tref;            // need to do this cause occasionally the globals get lost
  60.                                         // passing the address to the Shim (it switches zones)
  61.     SerialShimInterface    IntBlk;
  62.     
  63.     TraceMessage(0, kCRMName"- Entering InstallShimDrvr");
  64.     
  65.     err = LoadShim();
  66.     if (err == noErr)
  67.     {    
  68.         IntBlk.DRVRInName = kDRVRInName;
  69.         IntBlk.DRVROutName = kDRVROutName;
  70.         IntBlk.CRMName = kCRMName;
  71.         IntBlk.CRMIcon = (IconPtr)&CRMDeviceIcon;
  72.         IntBlk.MaxSpeed = kMaxBaudRate;
  73.         IntBlk.RefCon = 0;
  74.         IntBlk.ConnID = ConnID;
  75.         err = (*gGlobals->ShimInstall) (IntBlk, &Tref);
  76.         gGlobals->ShimRef = Tref;
  77.     }
  78.     
  79.     return err;
  80. }
  81.  
  82. /***********************************************************************************/
  83. //    Function:        RemoveShimDrvr(Boolean forceFlag)
  84. //    Description:    Handles the interface with the shim remove
  85. //
  86. //    Input:            Orderly or forced
  87. //    Output:            Results
  88. /***********************************************************************************/
  89.  
  90. OSErr RemoveShimDrvr(Boolean forceFlag)
  91. {    
  92.     OSErr     err;
  93.     
  94.     TraceMessage(0, kCRMName"- Entering RemoveShimDrvr");
  95.     
  96.     if (gGlobals->ShimRef != kInvalidRef)
  97.     {
  98.         err = (*gGlobals->ShimRemove) (gGlobals->ShimRef, forceFlag);
  99.         if (err == noErr)
  100.             UnLoadShim();
  101.             
  102.         if (err > 0)                // if it's pending the shim handles from here
  103.             err = noErr;            // but we can't unload yet
  104.             
  105.     } else {
  106.         err = -1;
  107.     }
  108.     
  109.     gGlobals->ShimRef = kInvalidRef;
  110.     return err;
  111. }
  112.  
  113. /***********************************************************************************/
  114. //    Function:        LoadShim
  115. //    Description:    Loads the shim and sets up the various addresses
  116. //
  117. //    Input:            Nothing
  118. //    Output:            Results
  119. /***********************************************************************************/
  120.  
  121. OSErr LoadShim(void)
  122. {
  123.     OSErr                err = noErr;            // Let's assume success
  124.     Ptr                    FragAddr;
  125.     CFragConnectionID    ConnID;
  126.     Str255                errMsg;
  127.     CFragSymbolClass    cClass;
  128.     
  129.     err = GetSharedLibrary("\pSerialShimLib", kPowerPCCFragArch, kLoadCFrag, &ConnID, &FragAddr, errMsg);
  130.     if (err == noErr)
  131.     {
  132.         gGlobals->ConnID = ConnID;
  133.         err = FindSymbol(ConnID, "\pSerialShimInstallDriver", (Ptr *)&gGlobals->ShimInstall, &cClass);
  134.         if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  135.         {
  136.             err = -1;
  137.         }
  138.         
  139.         if (err == noErr)
  140.         {
  141.             err = FindSymbol(ConnID, "\pSerialShimRemoveDriver", (Ptr *)&gGlobals->ShimRemove, &cClass);
  142.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  143.             {
  144.                 err = -1;
  145.             }
  146.         }
  147.         
  148.         if (err == noErr)
  149.         {
  150.             err = FindSymbol(ConnID, "\pSerialShimIOComplete", (Ptr *)&gGlobals->ShimComplete, &cClass);
  151.             if ((err != noErr) || (cClass != kTVectorCFragSymbol)) 
  152.             {
  153.                 err = -1;
  154.             }
  155.         }
  156.     }
  157.  
  158.     return err;
  159. }
  160.  
  161. /***********************************************************************************/
  162. //    Function:        UnLoadShim
  163. //    Description:    UnLoads the shim, actually closes the connection
  164. //
  165. //    Input:            Nothing
  166. //    Output:            Results
  167. /***********************************************************************************/
  168.  
  169. OSErr UnLoadShim(void)
  170. {
  171.     OSErr    err = noErr;            // Let's assume success
  172.     
  173.     err = CloseConnection(&gGlobals->ConnID);
  174.     
  175.     return err;
  176.  
  177. }
  178.  
  179. /***********************************************************************************/
  180. //    Function:        ShimIOComplete
  181. //    Description:    Sets up and calls the shim's completion routine
  182. //
  183. //    Input:            Parameter block and result code
  184. //    Output:            nothing
  185. /***********************************************************************************/
  186.  
  187. void     ShimIOComplete(ParmBlkPtr pb, OSErr result)
  188. {
  189.     pb->ioParam.ioResult = result;
  190.     (*gGlobals->ShimComplete) (gGlobals->ShimRef, (IOParam *)pb);
  191.  
  192. }